package com.hly.musicbackground.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hly.musicbackground.domain.FictionShelf;
import com.hly.musicbackground.model.boots.VO.FictionShelfVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface FictionShelfDao extends BaseMapper<FictionShelf> {

    @Update("update fiction_shelf set new_chapter = #{i} where fiction_id = #{id} and type = #{type}")
    void updateNewChapter(@Param("i") int i,@Param("id") int id, @Param("type") String type);

    @Select("select A.fiction_id as fictionId, A.fiction_chapter_id as fictionChapterId " +
            ", A.chapter_num as chapterNum, A.new_chapter as newChapter, A.update_time as updateTime " +
            ", A.type as type, B.update_time as newChapterTime, B.fiction_author as fictionAuthor " +
            ", B.fiction_name as fictionName, B.status as status, B.image as image " +
            "from fiction_shelf as A join fiction as B on A.fiction_id = B.fiction_id " +
            "where (A.type = #{type} or #{type} = 'all') and A.user_id = #{userId} and A.del = 0 " +
            "order by A.update_time desc " +
            "limit #{page},#{limit}")
    List<FictionShelfVO> getFictionShelfVOs(@Param("userId") int userId,
                                            @Param("type") String type,
                                            @Param("page") int page,
                                            @Param("limit") int limit);
}
